<template>
  <div class="qinghua">
    <el-tooltip :open-delay="1000" placement="top">
      <div slot="content">
        <span class="content_title">设备编号：</span>
        {{ id }}
        <br />
        <span class="content_title">设备状态：</span>
        {{ getHeadName(data.status) }}
        <br />
        <span class="content_title">生产品种：</span>
        R40SAA-1
        <br />
        <span class="content_title">设备效率：</span>
        {{ data.bodyVal }}%
      </div>
      <svg
        width="26px"
        height="19px"
        viewBox="0 0 26 19"
        version="1.1"
        xmlns="http://www.w3.org/2000/svg"
        xmlns:xlink="http://www.w3.org/1999/xlink"
      >
        <g
          id="大屏"
          stroke="none"
          stroke-width="1"
          fill="none"
          fill-rule="evenodd"
        >
          <g id="首页" transform="translate(-1725.000000, -315.000000)">
            <g id="编组-14" transform="translate(1726.000000, 316.000000)">
              <g
                id="编组-18备份-2"
                transform="translate(12.000000, 8.500000) scale(1, -1) translate(-12.000000, -8.500000) "
                :style="bodyStyle"
              >
                <path
                  d="M2,-1 L15,-1 C15.5522847,-1 16,-0.55228475 16,0 L16,16 L16,16 L1,16 L1,0 C1,-0.55228475 1.44771525,-1 2,-1 Z"
                  id="矩形备份-137"
                  :style="bodyStyle"
                  transform="translate(8.500000, 7.500000) rotate(-90.000000) translate(-8.500000, -7.500000) "
                ></path>
                <path
                  d="M13,4 L28,4 L28,10 C28,10.5522847 27.5522847,11 27,11 L14,11 C13.4477153,11 13,10.5522847 13,10 L13,4 L13,4 Z"
                  id="矩形备份-138"
                  :style="headStyle"
                  transform="translate(20.500000, 7.500000) rotate(-90.000000) translate(-20.500000, -7.500000) "
                ></path>
                <rect id="矩形" x="9" y="15" width="6" height="2"></rect>
              </g>
              <text
                id="3"
                font-family="PingFang-SC-Medium, PingFang SC"
                font-size="8"
                font-weight="400"
                letter-spacing="-0.5"
                fill="#FFFFFF"
              >
                <tspan x="6" y="12">{{ id }}</tspan>
              </text>
            </g>
          </g>
        </g>
      </svg>
    </el-tooltip>
  </div>
</template>

<script>
export default {
  name: 'qinghua',
  props: ['data'],
  data() {
    return {
      headStyle: {
        fill: ''
      },
      bodyStyle: {
        fill: ''
      },
      id: ''
    };
  },
  watch: {
    data: {
      deep: true, //true 深度监听
      immediate: true,
      handler(val) {
        this.draw();
      }
    }
  },

  mounted() {
    this.draw();
  },
  methods: {
    draw() {
      this.headStyle.fill = this.getHeadColor(this.data.status);
      this.bodyStyle.fill = this.getBodyColor(this.data.bodyVal);
      this.id = this.data.id;
    },
    //尾灯表示车台状态（运行、停止、故障、满纱满桶、通讯失败)
    getHeadColor(status) {
      switch (parseInt(status)) {
        //运行
        case 1:
          return '#7CBC44';
        //停止
        case 2:
          return '#888F93';
        //故障
        case 3:
          return '#6D000E';
        //满纱满桶
        case 4:
          return '#ECCD54';
        //通讯失败
        case 5:
          return '#EB4E27';
      }
    },
    //尾灯表示车台状态（运行、停止、故障、满纱满桶、通讯失败)
    getHeadName(status) {
      switch (status) {
        //运行
        case 1:
          return '运行';
        //停止
        case 2:
          return '停止';
        //故障
        case 3:
          return '故障';
        //满纱满桶
        case 4:
          return '满纱满桶';
        //通讯失败
        case 5:
          return '通讯失败';
      }
    },
    //车身颜色渐变表示车台当前效率范围
    getBodyColor(stateCode1) {
      let stateCode = Number(stateCode1) * 100;
      if (stateCode >= 90) {
        return '#2D69C7';
      } else if (90 > stateCode && stateCode >= 80) {
        return '#ECCD54';
      } else if (80 > stateCode && stateCode > 70) {
        return '#ECCD54';
      } else if (stateCode <= 70) {
        return '#EB4E27';
      }
    }
  }
};
</script>

<style lang="scss" scoped>
.cls-1 {
  fill: #3e8dcf;
}

.cls-1,
.cls-2,
.cls-4 {
  stroke: #82c4fa;
  stroke-width: 2px;
}

.cls-2,
.cls-4 {
  stroke-linejoin: round;
}

.cls-2 {
  fill-rule: evenodd;
  fill: url(#linear-gradient);
}

.cls-3 {
  font-size: 40px;
  fill: #fff;
  font-family: 'Microsoft YaHei';
  font-weight: 700;
}

.cls-4 {
  fill: #519aff;
}
</style>
